const app = getApp()
var util = require('../../utils/util.js')
var http = require('../../utils/http.js')

var audio = wx.createInnerAudioContext();

// 跳转部分
var skip_active = false; //跳转是否成功
var skip_rockon = null; //跳转定时器
var rockon = false; //是否跳转

// 在页面中定义激励视频广告
let videoAd = null
// 在页面中定义插屏广告
let interstitialAd = null
Page({
  data: {
    getUserInfo: false,
    inviteTasks: '',
    num: '',
    orderIndex: '',
    signRedlist: '',
    trueNum: '',
    money: '',
    totalNum: '',
    noteNum: '',
    isSign: '',
    signDay: '',
    yidongMask: false,
    fan: false,
    beforeOpen: false,
    giftIndex: '',
    giftArr: [
      '/million/1.png',
      '/million/2.png',
      '/million/3.png',
      '/million/4.png',
    ],
    second: 200,
    countOrder: -1,
    current: '',
    signRedArr: [],
    littleRed: [
      {
        src: '/sign/not_get.png',
        day: '第1天',
        have: '已领取',
        tag: '¥0.01',
      },
      {
        src: '/sign/not_get.png',
        day: '第2天',
        have: '已领取',
        tag: '¥0.01',
      },
      {
        src: '/sign/not_get.png',
        day: '第3天',
        have: '已领取',
        tag: '¥0.01',
      },
      {
        src: '/sign/not_get.png',
        day: '第4天',
        have: '已领取',
        tag: '¥0.01',
      },
      {
        src: '/sign/not_get.png',
        day: '第5天',
        have: '已领取',
        tag: '¥0.01',
      },
      {
        src: '/sign/not_get.png',
        day: '第6天',
        have: '已领取',
        tag: '¥0.01',
      }
    ],
    giftList: [
      {
        id: 0,
        src: '/million/gift_zero.png',
        txt: 'iPhone 11'
      },
      {
        id: 1,
        src: '/million/gift_one.png',
        txt: '超级现金红包'
      },
      {
        id: 2,
        src: '/million/gift_two.png',
        txt: '618大礼包'
      },
      {
        id: 3,
        src: '/million/gift_three.png',
        txt: '20个音符'
      },
      {
        id: 4,
        src: '/million/go.png',
        txt: ''
      },
      {
        id: 5,
        src: '/million/gift_three.png',
        txt: '5个音符'
      },
      {
        id: 6,
        src: '/million/gift_four.png',
        txt: '碎片x1'
      },
      {
        id: 7,
        src: '/million/gift_three.png',
        txt: '10个音符'
      },
      {
        id: 8,
        src: '/million/gift_four.png',
        txt: '碎片x3'
      },
    ],
    fiveTimes: false,
    welfare: false,
    openMask: false,
    millionMask: false,
    giftMask: false,
    order: '',
    five: false,
    zero: false,
    getingMask: false,
    signMask: false,
    ruleMask: false,
    pan: false,
    panDelayOne: false,
    panDelayTwo: false,
    panDelayThree: false,
    swiperList: [{
      img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911170490.jpeg",
      name: "张运豪",
      money: 86
    }, {
        img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911167600.jpeg",
      name: "此石、此刻",
      money: 59
    }, {
        img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911170326.jpeg",
      name: "猜猜",
      money: 56
    }, {
        img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911162735.jpeg",
      name: "幸福小女人",
      money: 87
    }, {
        img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911162735.jpeg",
      name: "豪琦卓越",
      money: 59
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911164205.jpeg',
      name: "貞ｌōｖé珺",
      money: 67
    }, {
        img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911164317.jpeg",
      name: "ʚ柠檬少女酱ɞ",
      money: 89
    }, {
        img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911168162.jpeg",
      name: "A布凡墙纸店",
      money: 105
    }, {
        img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911165438.jpeg",
      name: "独行者",
      money: 56
    }, {
        img: "https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911172779.jpeg",
      name: "不懂姐就别去猜",
      money: 98
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911172686.jpeg',
      name: "你好陌生",
      money: 50
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911473214.jpeg',
      name: "蓝带烤地瓜",
      money: 52.8
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911472266.jpeg',
      name: "犟丫头",
      money: 78.4
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911476085.jpeg',
      name: "快乐自由人",
      money: 65.7
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911473891.jpeg',
      name: "手工加工",
      money: 95
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911472695.jpeg',
      name: "A舒天红",
      money: 56.9
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911476939.jpeg',
      name: "陈红",
      money: 67.8
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911468741.jpeg',
      name: "改变自己",
      money: 85.5
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911472930.jpeg',
      name: "陈娜小号",
      money: 89
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911470603.jpeg',
      name: "旭日阳光",
      money: 97
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911471650.jpeg',
      name: "凝云冰兰",
      money: 69
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911472648.jpeg',
      name: "伴城烟雨",
      money: 58
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911468536.jpeg',
      name: "幸福家庭",
      money: 68
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911468165.jpeg',
      name: "海阔天空",
      money: 72
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911468838.jpeg',
      name: "一帆风顺小葡萄",
      money: 72.0
    }, {
        img: 'https://gxxc-1258879759.cos.ap-guangzhou.myqcloud.com/tree/utils/1543911471441.jpeg',
      name: "盘锦魏丽",
      money: 89.6
    }],
  },
  insertScreenAdTimer: '',
  //事件处理函数
  onLoad: function (options) {
    if(options) {
      var parentUserId = options.userId//邀请人的id
    }
    var that = this;
    //开关审核
    http.versionSwitch().then( res => {
      var isDelay = res.isReview;
      var isReview = res.isReview;
      var isReview1 = res.isReview1;
      wx.setStorageSync('isDelay',isDelay);
      wx.setStorageSync('isReview',isReview);
      wx.setStorageSync('isReview1',isReview1);
      that.setData({
        isReview
      })
    })
    //播放BGM音效
    audio.loop = true;
    audio.autoplay = true;
    audio.src = 'https://gxxc-1258879759.file.myqcloud.com/song1/indexBgm1.mp3';
    audio.onPlay( () => {
    util.log('开始播放')
    });
    audio.onError( (res) => {
    util.log(res.errMsg);
    util.log(res.errCode);
    })
    var userId = wx.getStorageSync('userId');
    var getUserInfo = wx.getStorageSync('getUserInfo');
    if( getUserInfo == '') {

    } else {
      that.setData({
        getUserInfo: true,
      })
    }
    if( userId == '') {
       //登录
       wx.login({
        success( res) {
          if(res.code) {
            const data = {
              code: res.code,
              parentUserId: parentUserId
            }
            wx.setStorageSync('code',res.code);
            //interface 1
            http.wxAmpLogin(data).then( res => {
              const userId = res.user.userId;
              const openId = res.user.openId;
              wx.setStorageSync('userId', userId)
              wx.setStorageSync('openId', openId)
              that.getUserInfo();
            })
          }
        } 
      })
    }
    // 在页面onLoad回调事件中创建激励视频广告实例
    if (wx.createRewardedVideoAd) {
      videoAd = wx.createRewardedVideoAd({
        adUnitId: 'adunit-96e23d22adce41d3'
      })
      videoAd.onLoad(() => {})
      videoAd.onError((err) => {})
      videoAd.onClose((res) => {
        if (res && res.isEnded || res === undefined) {
          console.log("我看完视频了");
          that.getVideoReward();
        } else {
          // 播放中途退出，进行提示
          wx.showToast({
            title: '观看广告时间不足，无法获得奖励',
            icon: "none",
            duration: 2000
          })
        }
      })
    }
    // 在页面onLoad回调事件中创建插屏广告实例
    if (wx.createInterstitialAd) {
      interstitialAd = wx.createInterstitialAd({
        adUnitId: 'adunit-7f5cc40bbeb7c980'
      })
      interstitialAd.onLoad(() => {})
      interstitialAd.onError((err) => {})
      interstitialAd.onClose(() => {})
    }
  },
screenAD: function() {
    // 在适合的场景显示插屏广告
    if (interstitialAd) {
      interstitialAd.show().catch((err) => {
      console.error(err)
      })
    }
  },
getVideoReward: function() {
  //看完视频后调用该接口
  var that = this;
  //看视频领取音符 interface 5
  http.watchVideoGetNote().then( (res) => {
    var noteNum = res.noteNum;//领取后的用户音符数量
    if( noteNum > 1000) {
      noteNum = Math.floor(noteNum/10000 *10)/10 + 'w';
    }
    that.setData({
      noteNum,
    })
  })
  },
  onShow: function () {
    var that = this;
    var random = Math.floor(Math.random()*2);
    that.setData({
      random
    })
    var now = new Date();
    var count = now.getTime();
    var newLimit = wx.getStorageSync("newLimit");
    console.log(newLimit)
    var insertScreenAdTimer = setInterval(function () {
      if( count > newLimit ) {
        that.screenAD();
        clearInterval(insertScreenAdTimer);
      }
    },1000)
    that.insertScreenAdTimer = insertScreenAdTimer;
    that.getUserInfo();
    audio.play();
    // 跳转其他小程序开始
		if (rockon == true) {
			rockon = false;
			console.log("跳转小程序");
			clearTimeout(skip_rockon)
			if (skip_active == true) {
				skip_active = false
				var adver = that.data.adver;
				var skip_index = that.data.skip_index;
				const data = {
						userId: wx.getStorageSync("userId"),
						advertisingId: adver[skip_index].id,
						appId: adver[skip_index].appId
				}
				http.tryRewared(data).then( res => {
          that.setData({
            noteNum: res.totalnoteNum,
          })
        })
			} else {
				wx.showModal({
					title: '提示',
				  content: "试玩时间不足20秒，无法获得奖励",
					showCancel: false,
				})
			}
		}
		// 跳转其他小程序结束
  },
  //获取用户信息接口
  getUserInfo: function() {
    var that = this;
    const data = {
      code: wx.getStorageSync('code')
    }
    const userId = wx.getStorageSync('userId');
    if(userId) {
      //interface 2
      http.getUserInfo(data).then( (res) => {
        var money = Math.floor( res.user.money / 10000 *100)/100;
        var totalNum = res.user.totalNum;
        var noteNum = res.user.noteNum;
        var littleRed =that.data.littleRed;
        if( noteNum > 1000) {
          noteNum = Math.floor(noteNum/10000 *10)/10;
        }
        var isSign = res.isSign;
        var signDay = res.signDay % 7;
        console.log(signDay)
        var signRedArr = wx.getStorageSync('signRedArr');
        if( signRedArr == '') {

        }
        that.setData({
          signRedArr,
        })
        if( signDay == 1) {
          littleRed[0].src = '/sign/current.png';
        } else if( signDay == 0 && res.signDay > 6) {
          for(var i = 0; i < 6; ) {
            littleRed[i].src = '/sign/already.png';
            littleRed[i].day = littleRed[i].have;
            i++;
          }
        } else {
            for( var i = 0; i < signDay ;) {
              if( i == signDay - 1 ) {
                littleRed[i].src = '/sign/current.png';
              } else {
                littleRed[i].src = '/sign/already.png';
                littleRed[i].day = littleRed[i].have;
              }
              i++;
            }
        }
        that.setData({
          littleRed
        })
        wx.setStorageSync('noteNum',noteNum);
        wx.setStorageSync('totalNum',res.user.totalNum);
        app.globalData.money = money;
        app.globalData.noteNum = noteNum;
        that.setData({
          money,
          totalNum,
          noteNum,
          isSign,
          signDay,
        })
      })
    }
  },
  //提现跳转界面
  withdraw: function () {
    wx.navigateTo({
      url: '/pages/withdraw/withdraw'
    })
  },
  // 双人擂台赛
  doubleRace: function() {

    //改回来等会策广告 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
    // wx.navigateTo({
    //   url: '/pages/fighting/fighting'
    // })



    //点击访问双人擂台赛界面，interface 8
    http.clickPK().then( res => {
        wx.navigateTo({
          url: '/pages/matching/matching'
        })
        console.log('进入匹配页面')
    }, err => {
      wx.showModal({
        title: '提示',
        content: err,
        showCancel: false
      })
    }) 
  },
  // 红包争夺赛
  redbagCompetition:function() {
//     var that = this;
//     var winNum = that.data.totalNum;
//     if( winNum >= 50) {
//       wx.navigateTo({
//         url: '/pages/session/session'
//       })
//     } else {
//       wx.showModal({
//         content: '获胜50场可开启',
//         showCancel: false
//       })
//  //改回来等会策广告 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
      wx.navigateTo({
        url: '/pages/session/session'
      })



//     }
  },
  // 规则
  rule:function() {
    this.setData({
      ruleMask: true,
    })
  },
  // 关闭规则弹窗
  closeRule: function() {
    var that = this;
    var isDelay = wx.getStorageSync('isDelay');
    var isDelayTime = Math.floor(Math.random()*1000);
    if( isDelay == 1) {
      setTimeout( () => {
        that.setData({
          ruleMask: false,
        })
      },isDelayTime)
    } else {
      that.setData({
        ruleMask: false,
      })
    }
  }, 
// 签到
sign: function () {
  var that = this;
  var isSign = that.data.isSign;
  if( isSign == 1) {
    wx.showModal({
      content: '今日已签到',
      showCancel: false
    })
    // that.setData({
    //   signMask: true,
    // })
  } else {
    //interface 3
    http.sign().then( res => {
      var signRedList = res.list;
      var signRedArr = [...that.data.signRedArr];
      var trueNum = res.trueNum;//抽中奖励
      var currentSign = that.data.signDay;
      that.setData({
        signMask: true,
      })
      if( currentSign == 0) {
        that.setData({
          trueNum,
          signRedList,
        })
      } else {
        var index  = parseInt(currentSign-1);
        signRedArr[index]= Math.floor(trueNum / 10000 *100) / 100;
        wx.setStorageSync('signRedArr',signRedArr);
        that.setData({
          signRedList,
          trueNum,
          signRedArr
        })
      }
    })
  }
},
// 叉掉签到弹窗
chacha:function() {
  this.setData({
    signMask: false,
  })
},
// 点击签到弹窗领取红包
dynamicRed:function() {
  var that = this;
  that.setData({
    beforeOpen: true,
    getingMask: true,
  })
  setTimeout(() => {
    that.setData({
      fan: true,
    })
  }, 1500);
  setTimeout(() => {
    that.setData({
      yidongMask: true,
      beforeOpen: false,
      fan: false,
    })
  }, 2500);
},
// 红包开始移动 
openRed: function(e) {
  var that = this;
  var order = e.currentTarget.dataset.order;
  that.setData({
    pan: true,
    order,
  })
  if( order == 1) {
    that.setData({
      panDelayOne: true,
      orderIndex: 2,
    })
  } else if( order == 2) {
    that.setData({
      panDelayTwo: true,
      orderIndex: 2,
    })
  } else {
    that.setData({
      panDelayThree: true,
      orderIndex: 2,
    })
  }
  setTimeout(() => {
    that.setData({
      getingMask: false,
      yidongMask: false,
      openMask: true,
    })
  },1000)
},
signDouble: function() {
  //看完视频调用翻倍接口
  //interface 4
  http.signDouble().then( res => {
    var that = this;
    that.setData({
      openMask: false,
      fiveTimes: true,
      five: true,
    })
  })
},
// 1到5倍领取
fiveMore: function() {
  var that = this;
  // 在页面onLoad回调事件中创建激励视频广告实例
  if (wx.createRewardedVideoAd) {
    videoAd = wx.createRewardedVideoAd({
      adUnitId: 'adunit-9e7297304053444f'
    })
    videoAd.onLoad(() => {})
    videoAd.onError((err) => {})
    videoAd.onClose((res) => {
      if (res && res.isEnded || res === undefined) {
        console.log("我看完视频了");
        that.signDouble();
      } else {
        // 播放中途退出，进行提示
        wx.showToast({
          title: '观看广告时间不足，无法获得奖励',
          icon: "none",
          duration: 2000
        })
      }
    })
  }
  // 用户触发广告后，显示激励视频广告
  if (videoAd) {
    videoAd.show().catch(() => {
      // 失败重试
      videoAd.load()
        .then(() => videoAd.show())
        .catch(err => {
          console.log('激励视频 广告显示失败')
        })
    })
  }
},
// 普通领取
zeroGet: function() {
  var that = this;
  that.setData({
    openMask: false,
    fiveTimes: true,
    zero: true,
  })
},
// 关闭1到5倍红包弹窗
closeFive:function() {
  var that = this;
  that.setData({
    signMask: false,
    fiveTimes: false,
    order: '',
    pan: false,
    panDelayOne: false,
    panDelayTwo: false,
    panDelayThree: false,
    five: false,
    zero: false,
  })
  that.onShow();
},
//投诉
complaint: function() {
  wx.navigateTo({
    url:'/pages/complaints/complaints'
  })
},
// 更多福利
moreWelfare: function() {
  var that = this;
  that.setData({
    welfare: true,
  })
  //邀请好友领取音符 interface 6
  http.friendTask().then( res => {
    var inviteTasks = res.inviteTasks;
    for(var i = 0; i < inviteTasks.length; i++){
      if(inviteTasks[i].haveNum >= inviteTasks[i].needNum) {
        const data = {
          id: inviteTasks[i].id,
        }
        //interface 7
        http.getInviteNote(data).then( res => {
          var noteNum = that.data.noteNum + res.num;
          that.setData({
            noteNum,
          })
        })
      }
    }
    that.setData({
      inviteTasks,
    })
  })
},
dayLook: function() {
  var that = this;
  // 用户触发广告后，显示激励视频广告
  if (videoAd) {
    videoAd.show().catch(() => {
      // 失败重试
      videoAd.load()
        .then(() => videoAd.show())
        .catch(err => {
          console.log('激励视频 广告显示失败')
        })
    })
  }
},
// 关闭免费音符弹窗
cha: function() {
  var that = this;
  var isDelay = wx.getStorageSync('isDelay');
  var isDelayTime = Math.floor(Math.random()*1000);
  if( isDelay == 1) {
    setTimeout( () => {
      that.setData({
        welfare: false,
      })
    },isDelayTime)
  } else {
    that.setData({
      welfare: false,
    })
  }
},
// 排行榜
rank: function() {
  wx.navigateTo({
    url: '/pages/rank/rank'
  })
},
// 跳转到砍价
discount: function() {
  wx.navigateTo({
    url: '/pages/discount/discount'
  })
},
//小程序跳转
stimulate: function() {
  // console.log("跳转")
  var that = this;
  that.setData({
    miniTurn: true,
  })
  that.advert();
},
// 广告 也包括小程序跳转
advert: function() {
  var self = this;
  const data = {
    openId: wx.getStorageSync('openId')
  }
  http.miniTurn(data).then( res => {
    var list = res.advertisingList;
    var video = null;
    var adver = [];
    var banner = null;
    var interst = [];
    for (var i = 0; i < list.length; i++) {
      if (list[i].advertisingType == 0) {
        video = list[i]
      }
      if (list[i].advertisingType == 1) {
        banner = list[i]
      }
      if (list[i].advertisingType == 7) {
        adver.push(list[i]);
      }
      if (list[i].advertisingType == 9) {
        interst = list[i]
      }
    }
    console.log(adver);
    wx.setStorageSync("adver_list", list)
    self.setData({
      video: video,
      adver: adver,
      banner: banner,
      // interst:interst
    })
    self.interst = interst
  })
},
  // 跳转去其他小程序
	skip: function(res) {
    var that = this;
    that.setData({
      miniTurn: false,
    })
		console.log(res);
		if (res.currentTarget.dataset.isclick == 1) {
			wx.navigateToMiniProgram({
				appId: res.currentTarget.dataset.appid,
				path: res.currentTarget.dataset.path,
				complete(data) {
					console.log("进入其他小程序成功");
					rockon = true;
					skip_rockon = setTimeout(function() {
						skip_active = true;
						that.setData({
							skip_index: res.currentTarget.dataset.index
						})
					}, 20000)
				}
			})
		} else {
			wx.navigateToMiniProgram({
				appId: res.currentTarget.dataset.appid,
				path: res.currentTarget.dataset.path,
				success(data) {
					console.log("进入其他小程序成功1");
				}
			})
		}
  },
closeTryPlay: function() {
  var that = this;
  var isDelay = that.data.isDelay;
  var delaySeconds =Math.floor(Math.random()*1000);
  if(isDelay == 1) {
    var delayTimer = setInterval(function () {
      that.setData({
        miniTurn: false,
      })
      clearInterval(delayTimer);
    },delaySeconds)
  } else {
    that.setData({
      miniTurn: false,
    })
  }
},
// 看视频抽奖，百万狂欢节
lottery: function(e) {
  var that = this;
  var countOrder = that.data.countOrder;
  var current = that.data.current;
  var giftIndex = that.data.giftIndex;
  var arr = [0,1,2,5,8,7,6,3,0,1,2,5,8,7,6,3,0,1,2,5,8,7,6,3,0,1,2,5,8,7,6,3,0,1,2,5,8,7,6,3];
  var orderMax = 34 + Math.floor(Math.random()*6);
  console.log(orderMax);
        var orderOne = setInterval(() => {
          if( countOrder < 24) {
            countOrder ++ ;
            current = arr[countOrder-1];
            that.setData({
              countOrder,
              current,
            })
          }
          else {
            clearInterval(orderOne);
            var orderTwo = setInterval(() => {
              if( countOrder >= 24 && countOrder < 28 ) {
                countOrder ++ ;
                current = arr[countOrder-1];
                that.setData({
                  countOrder,
                  current,
                })
              }else {
                clearInterval(orderTwo);
                var orderThree = setInterval(() => {
                  if( countOrder >= 28 && countOrder <= 33) {
                    countOrder ++ ;
                    current = arr[countOrder-1];
                    that.setData({
                      countOrder,
                      current,
                    })
                  } else {
                    clearInterval(orderThree);
                    var orderFour = setInterval(() => {
                      if (countOrder <= orderMax) {
                        current = arr[countOrder-1];
                        countOrder ++ ;
                        if( current == 1) {
                          giftIndex = 1;
                        } else if(current == 2) {
                          giftIndex = 0;
                        } else if( current == 5 || current == 7 || current == 3) {
                          giftIndex = 2;
                        } else {
                          giftIndex = 3;
                        }
                        that.setData({
                          countOrder,
                          current,
                          giftIndex,
                      })
                      } else {
                        clearInterval(orderFour);
                        that.setData({
                          giftMask: true,
                          countOrder: -1,
                      })
                      }
                    },200);
                  }
                },180)
              }
            },150)
          }
        },50)
},
//用户授权
bindGetUserInfo: function() {
  var that = this;
  wx.login({
    success: function(ress) {
      wx.getUserInfo({
        success: function(res) {
          const data = {
            code: ress.code,
            iv: res.iv,
            encryptedData: res.encryptedData
          }
          //interface 28
          http.authorization(data).then( res => {
            var getUserInfo = true;
            wx.setStorageSync('getUserInfo',getUserInfo)
            var res = res.user;
            var touxiang = res.userLogo;
            var loginName = unescape(res.realName);
            wx.setStorageSync('touxiang',touxiang);
            wx.setStorageSync('loginName',loginName);
            that.setData({
              getUserInfo,
            })
          })
        }
      })
    }
  })
},
// 百万狂欢节
million: function() {
  this.setData({
    millionMask: true,
  })
},
// 抽奖直接领取
giftGet: function() {
  this.setData({
    giftMask: false,
  })
},
// 关闭百万狂欢弹
millionCha: function() {
  this.setData({
    millionMask: false,
  })
},
onShareAppMessage: function() {
  var that = this;
  var userId = wx.getStorageSync('userId');
  return {
    title: '你的好友来给你送红包了，赶快点击领取',
    path: "/pages/index/index?userId=" +userId,
  }
},
onHide: function() {
  var that = this;
  audio.pause();
},
onUnload: function() {
  var that = this;
  audio.pause();
},
})

